﻿using PhotoKiosk.Model;
using PhotoKiosk.ViewModel.Helpers;
using PhotoKiosk.ViewModel.UserControls;
using System.Windows.Input;

namespace PhotoKiosk.ViewModel
{
    public class OrderDetailsViewModel : ViewModelBase
    {
        private readonly MainWindowViewModel m_mainWindowViewModel;
        private KeyboardAndTextViewModel m_keyboardAndTextViewModel;
        private NumbersPadAndTextViewModel m_numbersPadAndTextViewModel;
        private Customer m_customer;
        public OrderDetailsViewModel(MainWindowViewModel i_mainWindowViewModel)
        {
            m_mainWindowViewModel = i_mainWindowViewModel;
            m_customer = new Customer();
        }

        public KeyboardAndTextViewModel KeyboardAndTextViewModel
        {
            get
            {
                if (m_keyboardAndTextViewModel == null)
                {
                    m_keyboardAndTextViewModel = new KeyboardAndTextViewModel();
                }
                return m_keyboardAndTextViewModel;
            }
        }

        public NumbersPadAndTextViewModel NumbersPadAndTextViewModel
        {
            get
            {
                if (m_numbersPadAndTextViewModel == null)
                {
                    m_numbersPadAndTextViewModel = new NumbersPadAndTextViewModel();
                }
                return m_numbersPadAndTextViewModel;
            }
        }

        private DelegateCommand m_finishCommand;

        public ICommand FinishCommand
        {
            get
            {
                if (m_finishCommand == null)
                {
                    m_finishCommand = new DelegateCommand(param => this.finishCommandExecute());
                }
                return m_finishCommand;
            }
        }

        private void finishCommandExecute()
        {
            if (m_keyboardAndTextViewModel.IsValidText() && m_numbersPadAndTextViewModel.IsValidNumber())
            {
                m_mainWindowViewModel.SystemData.SetCustomer(new Customer() { Name = m_keyboardAndTextViewModel.Text, PhoneNumber = m_numbersPadAndTextViewModel.Number });
                m_mainWindowViewModel.CurrentViewModel = new PaperSelectViewModel(m_mainWindowViewModel);
            }
        }
    }
}
